package cndw.core.util;

import cndw.core.cfg.ServerConfig;
import cndw.core.dispatch.Request;

/**
 * 
 * @author zuojie.x
 */
public final class Sign {
	static final String SecretKey = ServerConfig.stringValue("SystemSecretKey");
	
	/**
	 * SIGN计算方法:md5(源串+密钥)<br/>
	 * 源串=request.getActionId()+secretKey<br/>
	 * 
	 * @param request
	 * @param secretKey
	 * @return sign
	 */
	public static String createSign(Request request) {
		StringBuilder builder = new StringBuilder(64);
		builder.append(request.getActionId());
		builder.append(SecretKey);
		return MD5.encode(builder.toString());
	}
	
	/**
	 * SIGN计算方法:md5(源串+密钥)<br/>
	 * 源串=request.getActionId()+secretKey<br/>
	 * 
	 * @param request
	 * @param secretKey
	 * @return sign
	 */
	public static String createSign(Request request, String secretKey) {
		StringBuilder builder = new StringBuilder(64);
		builder.append(request.getActionId());
		builder.append(secretKey);
		return MD5.encode(builder.toString());
	}
	
	public static String createSign(int actionId, String secretKey) {
		StringBuilder builder = new StringBuilder(64);
		builder.append(actionId);
		builder.append(secretKey);
		return MD5.encode(builder.toString());
	}
}
